<template>
  <div id="panel">
    <el-card>
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="概览" name="first">
          <overview :dmid="dmid" v-if="activeName === 'first'" />
        </el-tab-pane>
        <el-tab-pane label="水质状况分析" name="second">
          <waterQuality
            :dmid="dmid"
            v-if="activeName === 'second' && dmType == 'isauto'"
          />
          <waterQualitySg
            :dmid="dmid"
            v-if="activeName === 'second' && dmType == 'ismanul'"
          />
        </el-tab-pane>
        <el-tab-pane label="水质变化趋势" name="third">
          <waterChange
            :dmid="dmid"
            v-if="activeName === 'third' && dmType == 'isauto'"
          />
          <waterChangeSg
            :dmid="dmid"
            v-if="activeName === 'third' && dmType == 'ismanul'"
          />
        </el-tab-pane>
        <!-- 1. 直接使用计算属性title，无需手动维护data中的title -->
        <el-tab-pane :label="title" name="fourth">
          <waterCalendar
            :dmid="dmid"
            :dmtitle="dmtitle"
            v-if="activeName === 'fourth' && dmType == 'isauto'"
          />
          <waterCalendarSg
            :dmid="dmid"
            :dmtitle="dmtitle"
            v-if="activeName === 'fourth' && dmType == 'ismanul'"
          />
        </el-tab-pane>
      </el-tabs>
    </el-card>
  </div>
</template>
<script>
import { getOverview } from "@/api/waterBusiness/interface.js";
export default {
  props: {
    dmid: {
      type: String,
      default: "",
    },
    dmType: {
      type: String,
      default: "",
    },
    dmtitle: {
      type: String,
      default: "",
    },
  },
  name: "dmOneByOne",
  components: {
    // 概览
    overview: () => import("./components/overview"),
    // 水质状况分析：修复组件名大小写（Vue组件名推荐 PascalCase，避免引用错误）
    waterQuality: () => import("./components/waterQuality"),
    waterQualitySg: () => import("./components/waterQualitySg.vue"),
    // 水质变化趋势
    waterChange: () => import("./components/waterChange"),
    waterChangeSg: () => import("./components/waterChangeSg.vue"),
    // 水质日历
    waterCalendar: () => import("./components/waterCalendar"),
    waterCalendarSg: () => import("./components/waterCalendarSg.vue"),
  },
  data() {
    return {
      activeName: "first",
      // 2. 删除data中的title，由计算属性统一管理
    };
  },
  computed: {
    // 3. 修复计算属性：正确绑定依赖、返回对应标题
    title() {
      // 当切换到第四个标签（fourth）且类型为手动（ismanul）时，显示“水质月历”
      if (this.dmType === "ismanul") {
        return "水质月历";
      }
      // 其他情况（包括自动类型isauto、未切换到第四个标签）显示“水质日历”
      return "水质日历";
    },
  },
  methods: {
    handleClick(tab, event) {
      console.log(tab, event);
    },
  },
};
</script>
<style lang="scss" scoped>
#panel .el-card {
  margin: 10px;
}
</style>
